<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>审核列表(供应商)</title>
    <link rel="stylesheet" type="text/css" href="/manager/easyui/themes/default/easyui.css">
    <link rel="stylesheet" type="text/css" href="/manager/easyui/themes/icon.css">
    <script type="text/javascript" src="/manager/easyui/jquery.min.js"></script>
    <script type="text/javascript" src="/manager/easyui/jquery.easyui.min.js"></script>
	<script type="text/javascript">
	    //工具栏
	    var toolbar = [{
	        text: '添加',
	        iconCls: 'icon-edit',
	        handler: function () {  $('#dd').dialog('open');}
	    }];
	   $(function(){
	       $('#booklist').datagrid({  
				title:'审核列表',  
				iconCls:'icon-save',   
				// url:'json/datagrid_data1.json',
                url: "/manager/examine/findByPage?id="+[[${session.id}]],
				columns:[
				    [
					{field:'title',title:'审核标题',width:100,align:'center'},
					{field:'info',title:'审核备注',width:200,align:'center'},
					{field:'flag',title:'审核状态',width:80,align:'center', formatter: function (value) {
                            if (value==1){
                                return "审核通过";
                            }else if(value==0){
                                return "审核中"
                            }else{
                                return "审核驳回";
                            }
                        }},
                    {field:'info',title:'审核详情',width:200,align:'center'},
					{field:'bookid',title:'书籍详情',width:200,align:'center',formatter:function(value,row,index){
					          // return "<a href=''>查看</a>";
                            // console.log(111)
                            // console.log(value);
                        $("#echo-name").textbox("setValue",value);
                        return "<button type='submit' id='btn' onclick='openLook("+value+")'>查看书籍</button>";
					}}					
				]
                ],
				toolbar: toolbar,  
				pagination: true,//表示在datagrid设置分页              
               	pageSize: 5,
				singleSelect:true,
                pageList: [5,10,20]
			});

           // $("#btn").click(function(event){
           //     $('#echo').dialog('open');
           // }

		 //初始化查询栏
		 $("#submit_search").linkbutton({ iconCls: 'icon-search', plain: true })
            .click(function () {
                $('#dg').datagrid({ queryParams: form2Json("searchform") });   //点击搜索
            });
          
          //初始化修改窗口  
         $('#dd').dialog({
			    title: 'My Dialog',
			    width: 700,
			    height: 500,
			    closed: true,
			    cache: false,
			    href: '',
			    modal: true,
			    iconCls: 'icon-save',
                buttons: [{
                    text:'提交',
                    iconCls:'icon-ok',
                    handler:function(){
                        addExime();
                        alert('ok');
                        $('#dd').dialog("close");
                    }
                },{
                    text:'关闭',
                    handler:function(){
                        alert('cancel');;
                    }
                }]
			});


         // 初始化回显窗口
           $('#echo').dialog({
               title: 'My Dialog',
               width: 700,
               height: 500,
               closed: true,
               cache: false,
               href: '',
               modal: true,
               iconCls: 'icon-save'
           });


           // 给它添加一个按钮
           $('#dd-isbn').textbox({
               icons: [{
                   iconCls:'icon-add',
                   handler: function(e){
                       // 发送请求到后天，后台获取数据，返回到前台。
                       var isbn = $("#dd-isbn").val();
                       $.ajax({
                           url: "/manager/examine/getInfoFromThird",
                           data: {isbn: isbn},
                           dataType: 'json',
                           method:'get',
                           success: function (res) {
                               if (res.code ==200){
                                   console.log(111);
                                   console.log(res.data.bookname, res.data.isbn,res.data.price);
                                   $("#dd-bookname").textbox("setValue",res.data.bookname);
                                   $("#dd-isbn").textbox("setValue",res.data.isbn);
                                   $("#dd-price").textbox("setValue",res.data.price);
                                   // $('#username_modify').textbox('setValue',result.data.username);
                                   $("#dd-number").textbox("setValue",res.data.number);
                                   $("#dd-groupprice").textbox("setValue",res.data.groupprice);
                                   // $("#echo-layout").textbox("setValue",res.data.layout);
                                   // $("#echo-register").textbox("setValue",res.data.register);
                                   $("#dd-weight").textbox("setValue",res.data.weight);
                                   $("#dd-bookintroduce").textbox("setValue",res.data.bookintroduce);
                                   $("#dd-authorintroduce").textbox("setValue",res.data.authorintroduce);
                                   console.log(res.data.imgurl);
                                   $("#dd-imageurl").attr("src",res.data.imgurl);
                                   //向文本中放入url，供后面向后台发送请求传入
                                   $("#dd-url").textbox("setValue",res.data.imgurl);

                                   // $("##dd-imageurl").attr("value",res.data.imgurl)

                                   // JS foreaxh取值，但需要值名字一一对应
                                   // $.each(res.data,function(k,v){
                                   //     $("#echo-"+k).textbox("setvalue",v);
                                   // });
                                   $('#dd').dialog('open');
                               }
                           }

                       })
                       $(e.data.target).textbox('setValue', 'Something added!');
                   }
               }]
           })
	   });

        function openLook(value){
            console.log("开始显示");
            console.log(value);
            $.ajax({
                url:"/manager/book/findById",
                data:{id: value},
                datatype: 'json',
                method: "get",
                success: function (res) {
                    if (res.code ==200){
                        console.log(111);
                        console.log(res.data.bookname, res.data.isbn,res.data.price);
                        $("#echo-bookname").textbox("setValue",res.data.bookname);
                        $("#echo-isbn").textbox("setValue",res.data.isbn);
                        $("#echo-price").textbox("setValue",res.data.price);
                        // $('#username_modify').textbox('setValue',result.data.username);
                        $("#echo-number").textbox("setValue",res.data.number);
                        $("#echo-groupprice").textbox("setValue",res.data.groupprice);
                        $("#echo-layout").textbox("setValue",res.data.layout);
                        $("#echo-register").textbox("setValue",res.data.register);
                        $("#echo-weight").textbox("setValue",res.data.weight);
                        $("#echo-bookintroduce").textbox("setValue",res.data.bookintroduce);
                        $("#echo-authorintroduce").textbox("setValue",res.data.authorintroduce);

                        console.log(res.data.imgurl);
                        $("#echo-image").attr("src","http://192.168.4.8:8080/"+res.data.imgurl);

                       // JS foreaxh取值，但需要值名字一一对应
                       // $.each(res.data,function(k,v){
                       //     $("#echo-"+k).textbox("setvalue",v);
                       // });
                        $('#echo').dialog('open');
                    }
                }
            })

        }

	   function addExime() {

           var form_data = $('#ff')[0];
           // // 创建表单对象
           var formData = new FormData(form_data);

           $.ajax({
               url: "/manager/examine/addExamine",
               data:formData,
               dataType: 'json',
               method: 'POST',
               cache: false,
               // 告诉jQuery不要设置contentType
               // 相当于enctype="multipart/form-data"
               processData: false,
               // // 告诉jQuery不要处理请求参数
               contentType: false,
               success: function (res) {
                   if (res.code == 200){
                       alert("上传文件成功!");
                       $('#articlelist').datagrid("reload");
                   }
               }
           });
       }

        function searchExamine() {
            var bookname = $("#bookname").val();
            var isbn = $("#isbn").val();
            var supplierid = [[${session.id}]];
            // var title = $("#article_name").val();
            // let type = $("#article_type").combobox("getValue");
            // let mode = $("#article_mode").combobox("getValue");
            // console.log(1111111111111)
            // console.log(bookname);
            // console.log(isbn);
            // console.log(supplierid);
            $('#booklist').datagrid({
                queryParams:{
                    bookname, isbn, supplierid
                }
            });
        };
	</script>
</head>
<body>
   <form name="searchform" method="post" action="" id ="searchform">
    <td width="70" height="30"><strong>审核查询：</strong></td>
    <td height="30">
        <input id="bookname" type="text" name="keyword" size=20 placeholder="书籍名称"/>
        <input id="isbn" type="text" name="keyword" size=20 placeholder="ISBN"/>
    </td>
	<td>
        <a id="standardQueryBtn" href="#" class="easyui-linkbutton" data-options="iconCls:'icon-search'" onclick="searchExamine()">搜索</a>
	  <!--<button type="button" id="">查询</button>-->
	</td>
  </form>
  <table id="booklist"></table>
    <div id="dd">
           <div align="center" style="margin-top: 30px">
            <form id="ff" method="post">
            <div style="margin-bottom:20px">
                <input id="dd-bookname" class="easyui-textbox" name="bookname" style="width:50%" data-options="label:'书籍名称:',required:true">
            </div>
			 <div style="margin-bottom:20px">
                <input id="dd-isbn" class="easyui-textbox" name="isbn" style="width:50%" data-options="label:'ISBN:',required:true,validType:'email'">
            </div>
            <div style="margin-bottom:20px">
                <input id="dd-price" class="easyui-textbox" name="price" style="width:50%" data-options="label:'单价:',required:true,validType:'email'">
            </div>
			<div style="margin-bottom:20px">
                <input id="dd-number" class="easyui-textbox" name="number" style="width:50%" data-options="label:'数量:',required:true,validType:'email'">
            </div>
            <div style="margin-bottom:20px">
                <input id="dd-groupprice" class="easyui-textbox" name="groupprice" style="width:50%" data-options="label:'团购价:',required:true">
            </div>
			 <div style="margin-bottom:20px">
                <input id="dd-layout" class="easyui-textbox" name="layout" style="width:50%" data-options="label:'版次:',required:true">
            </div>
			<div style="margin-bottom:20px">
                <input id="dd-register" class="easyui-textbox" name="register" style="width:50%" data-options="label:'册数:',required:true">
            </div>
			<div style="margin-bottom:20px">
                <input id="dd-weight" class="easyui-textbox" name="weight" style="width:50%" data-options="label:'重量:',required:true">
            </div>
            <div style="margin-bottom:20px">
                <input id="dd-bookintroduce" class="easyui-textbox" name="bookintroduce" style="width:50%;height:60px" data-options="label:'书籍简介:',multiline:true">
            </div>
            <div style="margin-bottom:20px">
                <input id="dd-authorintroduce" class="easyui-textbox" name="authorintroduce" style="width:50%;height:60px" data-options="label:'作者简介:',multiline:true">
            </div>
             <div style="margin-bottom:20px">
               封面图片:&nbsp;&nbsp;&nbsp;&nbsp; <input  type="file" name="uploadFile"/>
            </div>
            <div>
                <img id="dd-imageurl"  src="" style='width:200px;'/>
            </div>
            <div style="margin-bottom:20px">
                <input id="dd-url" name="imgurl" class="easyui-textbox"  style="width:50%;height:60px" data-options="label:'URL:',multiline:true">
            </div>
        </form>
       </div>
    </div>


   <!--查看回显数据的div-->
   <div id="echo">
       <div align="center" style="margin-top: 30px">
           <form id="echoform" method="post">
               <div style="margin-bottom:20px">
                   <input id="echo-bookname" class="easyui-textbox" name="name" style="width:50%" data-options="label:'书籍名称:',required:true">
               </div>
               <div style="margin-bottom:20px">
                   <input id="echo-isbn" class="easyui-textbox" name="email" style="width:50%" data-options="label:'ISBN:',required:true,validType:'email'">
               </div>
               <div style="margin-bottom:20px">
                   <input id="echo-price" class="easyui-textbox" name="email" style="width:50%" data-options="label:'单价:',required:true,validType:'email'">
               </div>
               <div style="margin-bottom:20px">
                   <input id="echo-number" class="easyui-textbox" name="email" style="width:50%" data-options="label:'数量:',required:true,validType:'email'">
               </div>
               <div style="margin-bottom:20px">
                   <input id="echo-groupprice"class="easyui-textbox" name="subject" style="width:50%" data-options="label:'团购价:',required:true">
               </div>
               <div style="margin-bottom:20px">
                   <input id="echo-layout" class="easyui-textbox" name="subject" style="width:50%" data-options="label:'版次:',required:true">
               </div>
               <div style="margin-bottom:20px">
                   <input id="echo-register" class="easyui-textbox" name="subject" style="width:50%" data-options="label:'册数:',required:true">
               </div>
               <div style="margin-bottom:20px">
                   <input id="echo-weight" class="easyui-textbox" name="subject" style="width:50%" data-options="label:'重量:',required:true">
               </div>
               <div style="margin-bottom:20px">
                   <input id="echo-bookintroduce" class="easyui-textbox" name="message" style="width:50%;height:60px" data-options="label:'书籍简介:',multiline:true">
               </div>
               <div style="margin-bottom:20px">
                   <input id="echo-authorintroduce" class="easyui-textbox" name="message" style="width:50%;height:60px" data-options="label:'作者简介:',multiline:true">
               </div>
               <div style="margin-bottom:20px">
                   封面图片:&nbsp;&nbsp;&nbsp;&nbsp; <input  type="file"/>
               </div>
               <div>
                   <img id="echo-image" src="" style='width:200px;' />
               </div>
           </form>
       </div>
   </div>

</body>
</html>